unit uOperationParamColor;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ToolWin, Grids, DBGridEh, StdCtrls, DB;

type
  TfOperationParamColor = class(TForm)
    GroupBox1: TGroupBox;
    DBGridEh5: TDBGridEh;
    tbOperationParamColor: TToolBar;
    tbAddOperationParamColor: TToolButton;
    tbDelOperationParamColor: TToolButton;
    ColorDialog1: TColorDialog;
    procedure DBGridEh5Columns1EditButtons0Click(Sender: TObject;
      var Handled: Boolean);
    procedure DBGridEh5Columns2EditButtons0Click(Sender: TObject;
      var Handled: Boolean);
    procedure tbAddOperationParamColorClick(Sender: TObject);
    procedure tbDelOperationParamColorClick(Sender: TObject);
    procedure DBGridEh5GetCellParams(Sender: TObject; Column: TColumnEh;
      AFont: TFont; var Background: TColor; State: TGridDrawState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fOperationParamColor: TfOperationParamColor;

implementation

uses uDBData;

{$R *.dfm}

procedure TfOperationParamColor.DBGridEh5Columns1EditButtons0Click(
  Sender: TObject; var Handled: Boolean);
begin
  if(ColorDialog1.Execute) then
  begin
    fDBData.dOperationParamColor.DataSet.FieldByName('FontColor').Value := IntToStr(ColorDialog1.Color);
  end;
end;

procedure TfOperationParamColor.DBGridEh5Columns2EditButtons0Click(
  Sender: TObject; var Handled: Boolean);
begin
  if(ColorDialog1.Execute) then
  begin
    fDBData.dOperationParamColor.DataSet.FieldByName('BGColor').Value := IntToStr(ColorDialog1.Color);
  end;
end;

procedure TfOperationParamColor.tbAddOperationParamColorClick(
  Sender: TObject);
begin
  fDBData.InsertRecord(fDBData.dOperationParamColor);
end;

procedure TfOperationParamColor.tbDelOperationParamColorClick(
  Sender: TObject);
begin
  fDBData.DeleteRecord(fDBData.dOperationParamColor);
end;

procedure TfOperationParamColor.DBGridEh5GetCellParams(Sender: TObject;
  Column: TColumnEh; AFont: TFont; var Background: TColor;
  State: TGridDrawState);
var
  FontColor, BGColor: Integer;
begin
  if((not (Sender as TDBGridEh).DataSource.DataSet.IsEmpty)and((Sender as TDBGridEh).DataSource.DataSet.State <> dsEdit)and((Sender as TDBGridEh).DataSource.DataSet.State <> dsInsert)) then
  begin
    if(Column.Index = 0) then
    begin
      FontColor := (Sender as TDBGridEh).DataSource.DataSet.FieldByName('FontColor').AsInteger;
      BGColor := (Sender as TDBGridEh).DataSource.DataSet.FieldByName('BGColor').AsInteger;
      if((FontColor > 0)and(BGColor > 0))then
      begin
        AFont.Color := FontColor;
        Background := BGColor;
      end;
    end;
  end;
end;

end.
